//
//  MyLookHeader.m
//  PigMarket
//
//  Created by 张敬 on 2019/9/4.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MyLookHeader.h"

@interface MyLookHeader()

@property (nonatomic, strong) NSArray *icons;
@property (nonatomic, strong) NSArray *titles;

@end


@implementation MyLookHeader

#pragma mark - lifecycle methods

- (void)setupUI{
    
    [self addSubview:self.pigIcon];
    [self addSubview:self.pignameLab];
    [self addSubview:self.pignumLab];
    [self addSubview:self.checkLab];
    [self addSubview:self.inputShopBtn];
    
}

- (void)setupLayout{
    
    self.height = 180;
    {
        _pigIcon.size = CGSizeMake(50, 50);
        _pigIcon.mj_x = _pigIcon.mj_y = 15;
    }
    
    {
        _pignameLab.frame = CGRectMake(0, 0, KScreenWidth, 100);
        [_pignameLab sizeToFit];
        _pignameLab.mj_x = _pigIcon.right + 10;
        _pignameLab.mj_y = 15;
    }
    
    {
        _pignumLab.frame = CGRectMake(0, 0, KScreenWidth, 100);
        [_pignumLab sizeToFit];
        _pignumLab.width += 10;
        _pignumLab.height += 5;
        _pignumLab.mj_x = _pignameLab.right + 10;
        _pignumLab.mj_y = 15;
    }
    
    {
        _inputShopBtn.size = CGSizeMake(56, 27);
        _inputShopBtn.mj_y = 27;
        _inputShopBtn.mj_x = KScreenWidth - _inputShopBtn.width -15;
    }
    
    {
        _checkLab.size = CGSizeMake(200, 17);
        _checkLab.mj_x = _pigIcon.right + 10;
        _checkLab.mj_y = _pignameLab.bottom + 7;
    }
    
    {
        UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 80, KScreenWidth, 1)];
        self.line.path = path.CGPath;
        self.line.hidden = NO;
    }
    
    {
        CGFloat gap = (KScreenWidth - 100 - 40*3)/2.0;
        @weakify(self);
        [self.icons enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            @strongify(self);
            
            UIImageView *icon = [UIImageView new];
            icon.image = [UIImage imageNamed:obj];
            icon.size = CGSizeMake(40, 40);
            icon.mj_y = 95;
            icon.mj_x = 50 + (gap + 40)*idx;
            
            icon.tapBlock = ^{
                if (self.dealCheckBlock) {
                    self.dealCheckBlock(idx);
                }
            };
            [self addSubview:icon];
            
            UILabel *label = [UILabel makeLabelWithText:self.titles[idx] textColor:UIColorFromRGB(0x262626) font:mFont(14) textAliment:1];
            label.frame = CGRectMake(KScreenWidth/3.0*idx, icon.bottom + 10, KScreenWidth/3.0, 20);
            [self addSubview:label];
        }];
    }
}

#pragma mark - setter methods
#pragma mark - getter methods

- (UIImageView *)pigIcon{
    
    if (!_pigIcon) {
        _pigIcon = [[UIImageView alloc] init];
    }
    return _pigIcon;
}

- (UILabel *)pignameLab{
    
    if (!_pignameLab) {
        _pignameLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x262626) font:mMediumFont(16) textAliment:0];
    }
    return _pignameLab;
}

- (UILabel *)pignumLab{
    if (!_pignumLab) {
        _pignumLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0xF1935F) font:mFont(10) textAliment:1];
        _pignumLab.backgroundColor = UIColorFromRGB(0xFEF6EE);
        [self addShadowAndCircleCorner:_pignumLab.layer corner:3];
    }
    return _pignumLab;
}

- (UILabel *)checkLab{
    
    if (!_checkLab) {
        _checkLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x999999) font:mFont(12) textAliment:0];
    }
    return _checkLab;
}

- (UIButton *)inputShopBtn{
    
    if (!_inputShopBtn) {
        _inputShopBtn = [UIButton makeButtonWithText:@"去店铺" textColor:KWhiteColor font:mFont(12) textAliment:1 cornerRadius:5];
        [_inputShopBtn setBackgroundImage:[UIImage imageNamed:@"look_message"] forState:UIControlStateNormal];
        
        @weakify(self);
        _inputShopBtn.tapBlock = ^{
            @strongify(self);
            
            if (self.dealShopBlock) {
                self.dealShopBlock();
            }
        };
    }
    return _inputShopBtn;
}

- (NSArray *)icons{
    
    if (!_icons) {
        _icons = @[@"adopted_look_record", @"look_recipe", @"look_growthReport"];
    }
    return _icons;
}

- (NSArray *)titles{
    
    if (!_titles) {
        _titles = @[@"猪只档案", @"它的食谱", @"领养列表"];
    }
    return _titles;
}

@end
